package com.kdtech.analyse.news.ulinix;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.kdtech.entity.crawler.UrlMeta;
import com.kdtech.entity.data.NewsMeta;
import com.kdtech.utils.DateUtils;
import com.kdtech.utils.HtmlCleaner;
import com.kdtech.utils.StringUtils;
import com.kdtech.analyse.AnalyseNews;

/**
 * 乌孜哈勒网
 * @author Persh
 *
 */
public class XjgumaNewsAnalyse implements AnalyseNews {
	
	private static final String[] regex={
		"http://xjguma.com/[A-Za-z]*/[A-Za-z]*/[0-9]*.html"
	};
	
	
	
	public boolean isDetailPage(String url) {
		if(url.indexOf("kino")!=-1 
				|| url.indexOf("Itot")!=-1 
				|| url.indexOf("MTV")!=-1 
				|| url.indexOf("bazar")!=-1 
				|| url.indexOf("Hemmibap")!=-1 
				|| url.indexOf("game")!=-1
				|| url.indexOf("rasim")!=-1){
			return false;
		}
		for (int i=0; i < regex.length; i++) {
			if (url.matches(regex[i])) {
				return true;
			}
		}
		return false;
	}

	
	public NewsMeta parserHtml(UrlMeta urlMeta) {
		NewsMeta news=new NewsMeta();
		if (urlMeta.getHtml() == null) {
		}		
		String htmltxt=urlMeta.getHtml();
		String url=urlMeta.getUrl();		
				
		news.setUrl(url);		
		String title=null;
		String content=null;
		String author=null;
		Long date=null;
		Document doc=Jsoup.parse(htmltxt);
		title =doc.select("div.show_tima h2").text();
		content=HtmlCleaner.getContentHtml(url,doc.select("div.show_gpic_text"));
		date=DateUtils.matchDate(doc.select("div.xjguma_show_info").text());
		if(date==null){
			date=DateUtils.matchDate(doc.select("span.xjguma_info_date").text());
		}

		if(StringUtils.isBlank(title)){
		}
		news.setTitle(StringUtils.trimSpace(title));
		news.setContent(content);
		news.setAuthor(author);
		news.setDate(date);	
		
		return news;
	}
	
	

	

	
}
